package practice;

/**
 * 第七天练习
 */
public class Day7 {
    /**
     * 单词搜索
     * 输入：
     * ["XYZE","SFZS","XDEE"],"XYZZED"
     * 返回值：
     * true
     * 链接：https://www.nowcoder.com/practice/987f2981769048abaf6180ed63266bb2?tpId=196&tqId=39583&ru=/exam/oj
     */
    private int[] dpx = {0,0,1,-1};
    private int[] dpy = {1,-1,0,0};
    private boolean[][] vi;
    private int m = 0;
    private int n = 0;
    public boolean exist (String[] board, String word) {
        m = board.length;
        n = board[0].length();
        vi = new boolean[m][n];
        for(int i = 0; i < m; i++) {
            for(int j = 0; j < n; j++) {
                if(board[i].charAt(j) == word.charAt(0)) {
                    if(dfs(board,word,i,j,0)) {
                        return true;
                    }
                }
            }
        }
        return false;
    }
    private boolean dfs(String[] board,String word,int i,int j,int pos) {
        if(pos == word.length() - 1) {
            return true;
        }
        vi[i][j] = true;
        for(int k = 0; k < 4; k++) {
            int x = i + dpx[k];
            int y = j + dpy[k];
            if(x >= 0 && x < m && y >= 0 && y < n && !vi[x][y] && board[x].charAt(y) == word.charAt(pos+1)) {
                if(dfs(board,word,x,y,pos+1)) {
                    return true;
                }
            }
        }
        vi[i][j] = false;
        return false;
    }

    /**
     * 游游的you
     * 链接：https://www.nowcoder.com/questionTerminal/cd117803b3364b218a8b3dcc498dee25
     */
    public static void main1(String[] args) throws Throwable {
        Reader read = new Reader();
        int q = read.nextInt();
        for(int i = 0; i < q; i++) {
            int count = 0;
            int a = read.nextInt();
            int b = read.nextInt();
            int c = read.nextInt();
            int min = Math.min(Math.min(a,b),c);
            if(min != b) {
                count += (b - min - 1);
            }
            count += (min * 2);
            System.out.println(count);
        }
    }
    /**
     * 圆圈中最后剩余的数（约瑟夫环）
     * 链接：https://www.nowcoder.com/practice/f78a359491e64a50bce2d89cff857eb6?tpId=13&tqId=11199&ru=/exam/oj
     */
    public int LastRemaining_Solution (int n, int m) {
        int f = 0;
        for(int i = 2; i <= n; i++) {
            f = (f + m) % i;
        }
        return f;

    }
}
